#include "WordCloudSys.h"
#include "TextSys/TextSys.h"
#include "ResSystem/TexMgr.h"
void zh(int x, int y, int& nx, int& ny){
	nx = y;
	ny =479-x;
}
MyRGB::MyRGB(float pr,float pg,float pb)
{
	r = pr;
	g = pg;
	b = pb;
}

void WordCloudSys::AddWordCloud(WordCloud * wc)
{
	if(wc == 0)
		return;
	wc->fbobj = new FBObj;
	wc->fbobj->ResetFBObj(862,479,479.0 * 0.5);
	wc->vrgb = new vector<MyRGB>;
	for(int j = 0; j < wc->vs->size(); ++j)
	{
		float r = float(rand()% 10000)/ 10000.0;
		float g = float(rand()% 10000)/ 10000.0;
		float b = float(rand()% 10000)/ 10000.0;
		wc->vrgb->push_back(MyRGB(r,g,b));
	}
	wclist.insert(WordList::value_type(wclist.size(), wc));
	DrawWordClouds();
}

WordCloudSys::~WordCloudSys()
{


}

void WordCloudSys::DrawWordClouds()
{
	for(WordList::iterator it = wclist.begin(); it != wclist.end(); ++it)
	{
		WordCloud &wc = *(it->second);
		int x,y;
		wc.fbobj->ClearBuffer();
		wc.fbobj->BeginDraw();
		glEnable(GL_TEXTURE_2D);
// 		const TexUnit *tu = TexMgr::GetSingleton().GetTexUnit("OpenFile1");
// 		//DrawTex(tu->id,0,0,tu->width,tu->height);
		for(int i = 0; i < wc.vd->size(); ++i)
		{
			//printf("%f %f %f\n",(*wc.vrgb)[i].r,(*wc.vrgb)[i].g,(*wc.vrgb)[i].b);
			
			glColor3f((*wc.vrgb)[i].r,(*wc.vrgb)[i].g,(*wc.vrgb)[i].b);
			zh((*wc.ansx)[i], (*wc.ansy)[i],x,y);
			//printf("%s\n" ,(*wc.vs)[i].c_str());
			//printf("%d %d\n" ,x,y);
			VoyDrawText((*wc.vs)[i].c_str(),x,y,1000,500,(*wc.vd)[i]);
		}
		wc.fbobj->EndDraw();
	}
}
void WordCloudSys::DrawWordCloudsToScreen()
{
	for(WordList::iterator it = wclist.begin(); it != wclist.end(); ++it)
	{
		WordCloud &wc = *(it->second);
		glColor3f(1,1,1);
		
// 		int x,y;
// 		for(int i = 0; i < wc.vd->size(); ++i)
// 		{
// 			//printf("%f %f %f\n",(*wc.vrgb)[i].r,(*wc.vrgb)[i].g,(*wc.vrgb)[i].b);
// 			glEnable(GL_TEXTURE_2D);
// 			glColor3f((*wc.vrgb)[i].r,(*wc.vrgb)[i].g,(*wc.vrgb)[i].b);
// 			zh((*wc.ansx)[i], (*wc.ansy)[i],x,y);
// 			//printf("%s\n" ,(*wc.vs)[i].c_str());
// 			//printf("%d %d\n" ,x,y);
// 			VoyDrawText((*wc.vs)[i].c_str(),x,y,1000,500,(*wc.vd)[i]);
// 		}
		DrawTex(wc.fbobj->GetTexID(),0,0,wc.fbobj->GetWidth(), wc.fbobj->GetHeight());
		//VoyDrawText("aaaa",0,0,200,30,1);
		//DrawTex(30,0,0,500,500);
// 		glDisable(GL_TEXTURE_2D);
// 		glColor3f(1,0,0);
// 		glBegin(GL_LINE_LOOP);
// 		glVertex2f(0,0);
// 		glVertex2f(wc.fbobj->GetWidth() ,0);
// 		glVertex2f(wc.fbobj->GetWidth(),wc.fbobj->GetHeight() );
// 		glVertex2f(0,wc.fbobj->GetHeight() );
// 		glEnd();
	}
}
void WordCloudSys::PopWord(int wcid, int num)
{

}
void WordCloudSys::Resume(int wcid, int num)
{

}
void WordCloudSys::Adjust(int wcid, string targetstr, int newv)
{

}

SINGLETON_OUTER_DECLARE(WordCloudSys)